#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1;
const int M = 1e9 + 7;

string s;
int k;

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> s >> k;

    k--;
    sort(s.begin(), s.end());
    while(k--)
        next_permutation(s.begin(), s.end());
    cout << s << endl;
    
    return 0;
}